<template>
	<view>
		<view class="view_main">
			<view class="userInfo_view">
				<image :src="userInfo.header"></image>
				<text>{{userInfo.nickname}}</text>
			</view>
			<view class="button_view">
				<button size="mini" @click="switchUser">切换用户</button>
			</view>
		</view>
		<!-- 菜单栏 -->
		<view class="menu_view">
			<view class="view1" @click="addFriend">添加好友</view>
			<view @click="goToFriendRequestList">
				<uni-badge class="view1" size="normal" :text="count" absolute="rightTop" type="error">
					好友申请
				</uni-badge>
			</view>
			<view class="view1">我的钱包</view>
			<view class="view1">我的运动</view>
			<view class="view1">我的运动</view>
			<view class="view1">我的运动</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {
					nickname: "昵称",
					header: "/static/header.png"
				},
				count: 0
			}
		},
		onLoad() {
			var flag = this.$.isLogin();
			if (!flag) return;
			// 获取用户信息
			this.userInfo.nickname = this.$.getUser("nickname");
			this.userInfo.header = this.$.getImg(this.$.getUser("header"));
		},
		onShow() {
			this.queryCount();
		},
		methods: {
			// 登出
			switchUser() {
				// 清除令牌
				uni.removeStorageSync("loginToken");
				// 关闭当前用户的webSocket
				this.ws.closeWs();
				// 关闭当前页跳转到登录页
				uni.reLaunch({
					url: '/pages/login/login',
					success: (res) => {
						uni.showToast({
							title: "登出成功",
							icon: "success"
						})
					}
				})
			},
			addFriend() {
				uni.navigateTo({
					url: '/pages/queryFriends/queryFriends'
				})
			},
			queryCount() {
				this.$.ajax({
					url: '/friendsRequest/queryFriendRequestCount',
					success: (count) => {
						this.count = count;
					}
				});
			},
			goToFriendRequestList() {
				uni.navigateTo({
					url: '/pages/friend_request_list/friend_request_list'
				})
			}
		}
	}
</script>

<style lang="scss">
	.view_main {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		padding: 40rpx 50rpx;
		box-sizing: border-box;

		.userInfo_view {
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 150rpx;
				height: 150rpx;
				border-radius: 75rpx;
			}

			text {
				margin-left: 30rpx;
				font-weight: 900;
			}
		}

		.button_view {

			button {
				margin: 0px;
				background-color: #00A2FF;
				color: white;
				border: 0px;
				box-shadow: 10rpx 10rpx 10rpx gray;
			}

			button:active {
				background-color: #0094e3;
				position: relative;
				left: 5rpx;
				top: 5rpx;
				box-shadow: 5rpx 5rpx 10rpx gray;
			}
		}
	}

	.menu_view {
		margin-top: 20rpx;
		padding: 40rpx;
		box-sizing: border-box;
	}

	.menu_view .view1 {
		width: 100%;
		box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
		margin-bottom: 20rpx;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
	}
</style>